package Hxw3DEngine.core.display
{
	import Hxw3DEngine.core.component.renderer.MeshRenderer;
	import Hxw3DEngine.core.materials.Material3D;
	import Hxw3DEngine.asset.parsers.bson.vo.Stream;
	import Hxw3DEngine.core.Resource.geometry.ResourceGeometry;
	
	//一个矩形
	public class Rectangle3D extends GameObject
	{
		
		private var width:Number = 100;
		
		private var height:Number = 100;
		
		public function Rectangle3D(_material:Material3D, w:Number = 100,h:Number = 100)
		{
			width = w;height = h;
			
			var vertexdata:Vector.<Number> = Vector.<Number>([
				//x,y,z
				-width/2,height/2,0,
				width/2,height/2,0,
				-width/2,-height/2,0,
				width/2,-height/2,0
				
			]);
			
			var uvdata:Vector.<Number> = Vector.<Number>([
				0,0,
				0,1,
				1,0,
				1,1
			]);
			
			
/*			uvdata = Vector.<Number>([
				0.75,0.25,1,0.25,0.75,0.5,1,0.5
			]);*/
			
			
			var indexdata:Vector.<uint> = Vector.<uint>([
				0,1,2,1,3,2
			]);
			
			var comp:MeshRenderer = new MeshRenderer();
			addComponent(comp);
			comp.geometry = new ResourceGeometry();
			comp.geometry.createFromStreams(indexdata, 4, [
					Stream.fromVector(Stream.stream_positions, vertexdata),
					Stream.fromVector(Stream.stream_uvs_1, uvdata)
				]);	
			comp.material = _material;
		}
	}
}